part of '../fhare.dart';

extension StringActionExt on String {
  ActionChip actionChip(VoidCallback? onPressed, {Color? color, double paddingX = 8, double elevation = 3}) {
    return ActionChip(label: text(color: color).paddings(hor: paddingX), elevation: elevation, onPressed: onPressed);
  }

  @Deprecated("Use actionX instead.")
  XAction actionItem(XActionCallback callback, {bool checked = false}) {
    return XAction(this, callback: callback, checked: checked);
  }

  XAction actionX(XActionCallback callback, {bool checked = false}) {
    return XAction(this, callback: callback, checked: checked);
  }

  XAction action(VoidCallback callback, {bool checked = false}) {
    return XAction(this, action: callback, checked: checked);
  }

  RawChip rawChip({
    ChipThemeData? defaultProperties,
    Widget? avatar,
    TextStyle? labelStyle,
    EdgeInsetsGeometry? padding = const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
    VisualDensity? visualDensity,
    EdgeInsetsGeometry? labelPadding,
    Widget? deleteIcon,
    void Function()? onDeleted,
    Color? deleteIconColor,
    String? deleteButtonTooltipMessage,
    void Function()? onPressed,
    void Function(bool)? onSelected,
    double? pressElevation,
    bool tapEnabled = true,
    bool selected = false,
    bool isEnabled = true,
    Color? disabledColor,
    Color? selectedColor,
    String? tooltip,
    BorderSide? side,
    OutlinedBorder? shape,
    Clip clipBehavior = Clip.none,
    FocusNode? focusNode,
    bool autofocus = false,
    WidgetStateProperty<Color?>? color,
    Color? backgroundColor,
    MaterialTapTargetSize? materialTapTargetSize,
    double? elevation = 3,
    Color? shadowColor,
    Color? surfaceTintColor,
    IconThemeData? iconTheme,
    Color? selectedShadowColor,
    bool? showCheckmark,
    Color? checkmarkColor,
    ShapeBorder avatarBorder = const CircleBorder(),
    BoxConstraints? avatarBoxConstraints,
    BoxConstraints? deleteIconBoxConstraints,
    ChipAnimationStyle? chipAnimationStyle,
  }) {
    return RawChip(
        label: this.text(),
        padding: padding,
        defaultProperties: defaultProperties,
        avatar: avatar,
        labelStyle: labelStyle,
        visualDensity: visualDensity,
        labelPadding: labelPadding,
        deleteIcon: deleteIcon,
        onDeleted: onDeleted,
        deleteIconColor: deleteIconColor,
        deleteButtonTooltipMessage: deleteButtonTooltipMessage,
        onPressed: onPressed,
        onSelected: onSelected,
        pressElevation: pressElevation,
        tapEnabled: tapEnabled,
        selected: selected,
        isEnabled: isEnabled,
        disabledColor: disabledColor,
        selectedColor: selectedColor,
        tooltip: tooltip,
        side: side,
        shape: shape,
        clipBehavior: clipBehavior,
        focusNode: focusNode,
        autofocus: autofocus,
        color: color,
        backgroundColor: backgroundColor,
        materialTapTargetSize: materialTapTargetSize,
        elevation: elevation,
        shadowColor: shadowColor,
        surfaceTintColor: surfaceTintColor,
        iconTheme: iconTheme,
        selectedShadowColor: selectedShadowColor,
        showCheckmark: showCheckmark,
        checkmarkColor: checkmarkColor,
        avatarBorder: avatarBorder,
        avatarBoxConstraints: avatarBoxConstraints,
        deleteIconBoxConstraints: deleteIconBoxConstraints,
        chipAnimationStyle: chipAnimationStyle);
  }
}

extension StringSizeExt on String {
  Size sizeDisplay({TextStyle? style, Locale? locale}) {
    if (this.isEmpty) return Size.zero;
    TextPainter p = TextPainter(text: TextSpan(text: this, style: style), maxLines: 1, locale: locale);
    p.layout();
    return p.size;
  }
}
